package Review;

public class Test41 {

	public static void main(String[] args) {
		int array[]={1,2,4,6,8,9,12};
		findSum(array,13);
		findSumOfTwoNum(array,13);
	}
	public static void findSum(int[] array,int sum){
		if(array==null||array.length==0){
			return;
		}
		int i= 0;
		int j= array.length-1;
		while(i<j){
			if(array[i]+array[j]>sum){
				j--;
			}
			else if(array[i]+array[j]<sum){
				i++;
			}
			else{
				System.out.println(array[i]+" "+array[j]);
				break;
			}
		}
	}
	public static void findSumOfTwoNum(int[] array,int sum){
		if(array==null||array.length==0){
			return;
		}
		int i = 0;
		int j = array.length - 1;
		while(i < j){
			int tmp = array[i] + array[j];
			if (tmp == sum) {
				System.out.println(array[i] +" "+ array[j]);
				break;
			}else if(tmp > sum){
				j --;
			}else{
				i ++;
			}
		}
	}
}
